package pri.hillchen.springbootstd.sso.common.page;

import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author:hillchen
 * @DESCRIPTION:
 * @Date: Created in 9:42 2017/12/26 0026.
 */
public class PageRecode<T> {
    private PageInfo pageInfo;
    private List<T> pageRecodes;
    private long total;

    public PageRecode() {
        this.pageInfo = new PageInfo();
    }

    public PageRecode(PageInfo pageInfo) {
        if(pageInfo == null){
            pageInfo = new PageInfo();
        }
        this.pageInfo = pageInfo;
    }

    public PageRecode(PageInfo pageInfo, List<T> pageRecodes, long total) {
        if(pageInfo == null){
            pageInfo = new PageInfo();
        }
        this.pageInfo = pageInfo;
        this.pageRecodes = pageRecodes;
        this.total = total;
    }

    public PageRecode(List<T> pageRecodes, long total) {
        this(new PageInfo(),pageRecodes,total);
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        if(total <0 ){
            total = 0;
        }
        this.total = total;
    }

    public void setPageSize(int pageSize) {
        this.pageInfo.setPageSize(pageSize);
    }

    public void setPageNo(int pageNo) {
        this.pageInfo.setPageNo(pageNo);
    }

    public PageInfo getPageInfo() {
        return pageInfo;
    }

    public List<T> getPageRecodes() {
        return pageRecodes;
    }

    public void setPageRecodes(List<T> pageRecodes) {
        this.pageRecodes = pageRecodes;
    }

    public boolean isEmpty(){
        return CollectionUtils.isEmpty(pageRecodes);
    }

    public long pageCounts(){
        return total / pageInfo.getPageSize() + (total % pageInfo.getPageSize() == 0 ? 0 : 1);
    }

}
